package com.example.outdoor;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class ListOfObstraction  extends Activity {
	 ListView lisView1;
		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.editobstraction);
		
			final myDBObstraction myDb = new myDBObstraction(this);
			final ArrayList<HashMap<String, String>> MebmerList = myDb.SelectAllData();   
			
	        // listView1
	        lisView1 = (ListView)findViewById(R.id.listViewObstraction); 
	        
	        SimpleAdapter sAdap;
	        sAdap = new SimpleAdapter(ListOfObstraction.this, MebmerList, R.layout.edit_obstraction_column,
	                new String[] {"ID", "Obstruction"}, new int[] {R.id.ColObsID, R.id.ColObs});      
	        lisView1.setAdapter(sAdap);
	        
	        lisView1.setOnItemClickListener(new OnItemClickListener() {
			      public void onItemClick(AdapterView<?> myAdapter, View myView, int position, long mylng) {
			    	   
			    	  	// Show on new activity
		            	Intent newActivity = new Intent(ListOfObstraction.this,UpdateObstraction.class);
		            	newActivity.putExtra("ID", MebmerList.get(position).get("ID").toString());
		            	startActivity(newActivity);

			      }       
	        });
			   
			
			// btnCancel (Cancel)
	        final Button cancel = (Button) findViewById(R.id.btnobsListCancel);
	        cancel.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {        	
	            	// Open Form Main
	            	Intent newActivity = new Intent(ListOfObstraction.this,EditTables.class);
	            	startActivity(newActivity);
	            }
	        });
	        
		}

}
